/**
 * 
 */
package solution.bit;

import junit.framework.Assert;

import org.junit.Test;

/**
 * @author <a href="www.sureinterview.com">SureInterview</a>
 * 
 */
public class NextLargestNumberOfSame1Bits {

	int nextNum(int i) {
		// the last 1 bit
		int lastBit = (i & ~(i - 1));

		return ((i + lastBit) | i) & ~lastBit;
	}

	@Test
	public void test() {
		Assert.assertEquals(0, nextNum(0));
		Assert.assertEquals(0x16, nextNum(0x13));
		Assert.assertEquals(0x1c, nextNum(0x16));
	}

}
